package controllers

import (
	"fmt"
	"gitee.com/linxunsdut/cncf01/utils"
	"github.com/golang/glog"
	"io"
	"net/http"
	"os"
)

func Healthz(w http.ResponseWriter, r *http.Request) {
	body := "the url path is" + r.URL.Path + "\n"
	glog.Infoln(body)
	io.WriteString(w, body)
}

func Env(w http.ResponseWriter, r *http.Request) {
	// SET VERSION
	os.Setenv("VERSION", "1.0.1")
	version := os.Getenv("VERSION")

	// Set Request Header
	for key, headerVL := range r.Header {
		// range header value list
		for _, v := range headerVL {
			w.Header().Set(key, v)
		}
	}

	// get ip
	ip := utils.ClientIP(r)
	body := fmt.Sprintf("Version : %s, \n your ip: %s\n", version, ip)
	io.WriteString(w, body)

	// Log
	glog.Info(body)
}
